<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title  style="display: none;">就诊</title>
    <titleType style="display: none;">jz</titleType>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.0&key=df32e70e30e59ee3a8081a1e0f9e7e52"></script>
    <%- include('../../_global/baseLibs') %>
    <!--<script src="/web/js/jkcs-util.js"></script>-->
</head>
<body>
<section class="page-wrap page-treatment">
    <header class="header-box fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0)"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="title">就诊</div>
            <!--<div class="right-tool">-->
            <!--<a href=""><i class="icon-tool-msg"><span class="number">0</span></i></a>-->
            <!--</div>-->
        </div>
    </header>

    <!--map test-->
    <div id="container">

    </div>
    <!--map test-->

    <aside class="hospital-top-info">
        <img class="img-response" src="/static/images/teatment/jz-hospital-pic.png"/>
    </aside>
    <aside class="hospital-top-text">
        <div class="text-wrap">
            <span class="name" name="hosName"></span>
            <span class="leave"><span name="yyjbmc"></span><span name="yydjmc"></span></span>
            <span class="typeof" name="isMedicareMc"></span>
        </div>
        <p class="address"><i class="icon icon-map"></i><span name="hosAddress"></span></p>
        <p class="phone"><i class="icon icon-phone"></i><span name="lxdh"></span></p>
    </aside>
    <aside class="change-hospital">
        <a id="change-hospital" class="change-a" title="选择医院" href="/html/gzd/myOrder/yygh.html?from=treatment">更换医院<i
                    class="iconfont"></i></a>
    </aside>

    <!-- list start -->
    <aside class="hospital-list-box">
        <ul class="row default-list">
            <li class="col-xs-6 runDiv" module="yygh">
                <a class="item">
                    <div class="item-inner">
                        <i class="icon icon-jz-yygh"></i>
                        <div class="item-center">
                            <h4 class="name">预约挂号</h4>
                            <p class="text">提前预约免排队</p>
                        </div>
                    </div>
                </a>
            </li>
            <li class="col-xs-6 business-module runDiv" module="xsjf">
                <a class="item">
                    <div class="item-inner">
                        <i class="icon icon-jz-xsjf"></i>
                        <div class="item-center">
                            <h4 class="name">线上缴费</h4>
                            <p class="text">在线支付免排队</p>
                        </div>
                    </div>
                </a>
            </li>
            <li class="col-xs-6 business-module runDiv" module="hzxx">
                <a class="item"  title="候诊信息">
                    <div class="item-inner">
                        <i class="icon icon-jz-hzxx"></i>
                        <div class="item-center">
                            <h4 class="name">候诊信息</h4>
                            <p class="text">排队情况实时查询</p>
                        </div>
                    </div>
                </a>
            </li>
            <li class="col-xs-6 business-module runDiv" module="ssjl">
                <a class="item"  title="检查检验单">
                    <div class="item-inner">
                        <i class="icon icon-jz-ssjl"></i>
                        <div class="item-center">
                            <h4 class="name">手术记录</h4>
                            <p class="text">快速查询手术情况</p>
                        </div>
                    </div>
                </a>
            </li>
            <li class="col-xs-6">
                <a  id="clickTo">
                    <div class="item-inner">
                        <i class="icon icon-yygk"></i>
                        <div class="item-center">
                            <h4 class="name">医院概况</h4>
                            <p class="text">查看医院简介</p>
                        </div>
                    </div>
                </a>
            </li>
            <li class="col-xs-6 business-module runDiv" module="tztg">
                <a href="">
                    <div class="item-inner">
                        <i class="icon icon-tztg"></i>
                        <div class="item-center">
                            <h4 class="name">通知通告</h4>
                            <p class="text">医生停诊告知</p>
                        </div>
                    </div>
                </a>
            </li>
            <!-- <li class="col-xs-6 business-module">
                <a href="/html/adapter/yygh/hosDetail.html?HOSDETAIL_TAB=2">
                    <div class="item-inner">
                        <i class="icon icon-kspb"></i>
                        <div class="item-center">
                            <h4 class="name">科室排班</h4>
                            <p class="text">医院科室排班信息</p>
                        </div>
                    </div>
                </a>
            </li> -->
            <!-- <li class="col-xs-6 business-module">
                <a href="">
                    <div class="item-inner">
                        <i class="icon icon-yntc"></i>
                        <div class="item-center">
                            <h4 class="name">院内停车</h4>
                            <p class="text">医院停车位置地图</p>
                        </div>
                    </div>
                </a>
            </li> -->
        </ul>
    </aside>
    <!-- list end -->
</section>
<!--footer-->
<%- include('../common/footer') %>

<script type="text/javascript">
    var map,hosData;


    var tb_zy_yyjb = {
        "1": "一级"
        , "2": "二级"
        , "3": "三级"
    }

    var tb_zy_yydj = {
        "0": "特等"
        , "1": "甲等"
        , "2": "乙等"
        , "3": "丙等"
    }

    var requestYydm = StoreCache.getCache("YYGH_HOSINFO")?StoreCache.getCache("YYGH_HOSINFO"):"";
    var requestYydm2 =true;



    function queryYyxx(params){
        params["location"] = params["longitude"]+","+params["latitude"];
        params["sortType"] = "1";
        params["mapType"] = "AMap";
        params["pageNum"] = 1;
        params["pageSize"] = 1;
        $.QuickRemote.AjaxJson("/api/jkcsHt/treatment/queryHos", page_treatment.queryHosHandler, params);
    }



    var page_treatment = (function($, page_treatment) {


        //解析定位结果
        function onLocationComplete (data) {
            // alert(data);
//            console.data(data)
//            var str=['定位成功'];
//            str.push('经度：' + data.position.getLng());
//            str.push('纬度：' + data.position.getLat());
            //通过经纬度计算两点之间的距离得出最近的一样
            var Lng=data.longitude!=undefined?data.longitude:data.position.getLng();
            var Lat=data.latitude!=undefined?data.latitude:data.position.getLat();

            var lnglat = new AMap.LngLat(Lng, Lat);
            var Disance=[];
            $.each(hosData,function(index,data){
                var location=data.hoslocation.split(',');
                Disance.push(lnglat.distance([location[0],location[1]]));
                // alert(lnglat.distance([location[0],location[1]]));
            });

            //获取最小值
            var min = Math.min.apply(null,Disance);
            //获取最小值索引
            var min_index = Disance.indexOf(min);

            page_treatment.initDataByYydm(hosData[min_index].yydm);
        };


        function initView() {
            /**信息调用方法*/
            $.JkcsUtils.jsbridgeRegister("indexRight", function(){
                // $.JkcsUtils.nativePermission({"type": "contacts", "callBackMethod": "noBack"});
            });

            $.JkcsUtils.jsbridgeRegister("scFunction", page_treatment.scFunction);

            $.JkcsUtils.jsbridgeRegister("onLocationComplete", page_treatment.onLocationComplete);

            $("body").on("click", ".business-module,.change-hospital", function () {
                var a = $(this).children("a:eq(0)");
                var href = $(a).attr("href");
                var title = $(a).attr("title");
                if (StringUtils.isEmpty(href)) {
                    $.QuickAlert.alertFail({
                        content: "功能尚未开发，敬请期待"
                    });
                } else {
                    var YYGH_HOSINFO = $("body").data("YYGH_HOSINFO");
                    StoreCache.setCache("YYGH_HOSINFO", YYGH_HOSINFO);
                    var param = {};
                    param["url"] = href;
                    param["app_user_agent"] = "jkcs";
                    if (title != null || title != 'undefined')
                        param['title'] = title;
                    $.QuickUrlUtils.redirectJSBridge(param);
                }
                /**取消a href默认的事件行为*/
                return false;
            })
        }

        function initDataByYydm(yydm) {
            $.QuickRemote.AjaxJson("/api/gzd/yygh/getHospitalList", page_treatment.queryHosHandler, {hoscode:yydm});
        }

        function initData() {

            var params = {};

            var currentLocationHos=function(){

                //
                // =>所有医院的经纬度信息查找最近医院
                var GDmapUntil=function(){
                    /***************************************
                     由于Chrome、IOS10等已不再支持非安全域的浏览器定位请求，为保证定位成功率和精度，请尽快升级您的站点到HTTPS。
                     ***************************************/
                    var  geolocation;

                    //解析定位错误信息
                    var onError=function (data) {
                        layer.open({
                            content: '定位失败！'
                            ,btn: '我知道了'
                        });
                    };
                    //加载地图，调用浏览器定位服务
                    map = new AMap.Map('container', {
                        resizeEnable: true
                    });

                    if(ServiceType!='mobile'){
                        map.plugin('AMap.Geolocation', function() {
                            geolocation = new AMap.Geolocation({
                                noIpLocate:1,
                                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                                timeout: 10000,          //超过10秒后停止定位，默认：无穷大
                                buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                                zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                                buttonPosition:'RB'
                            });
                            map.addControl(geolocation);
                            geolocation.getCurrentPosition();
                            AMap.event.addListener(geolocation, 'complete', page_treatment.onLocationComplete);//返回定位信息
                            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
                        });
                    }else{
                        $.JkcsUtils.nativePermission({
                            "type": "location",
                            "callBackMethod": "page_treatment.onLocationComplete",
                            "params": params
                        });

                    }
                }

                var requestRoot = "/jkcsHt/yygh";
                $.QuickRemote.AjaxJson("/api"+requestRoot + "/getPlaceList", function(result) {
                    //console.log(result);
                    if(result["code"] == "0"){
                        /**解析行政区划*/
                        var data  = result["data"];
                        var xzqhs = [];
                        var li = $($("#xzqhLi").html());
                        $(li).attr("value","0");
                        $(li).find("a").html("全部区域")
                        xzqhs.push($(li));
                        $(data).each(function(index, item){
                            var xzqhLi = $($("#xzqhLi").html());
                            $(xzqhLi).attr("value",item["xzqhdm"]);
                            $(xzqhLi).find("a").html(item["xzqhmc"]);
                            xzqhs.push(xzqhLi);
                        });
                        //console.log(xzqhs);
                        $("#xzqhUl").empty();
                        $("#xzqhUl").append(xzqhs);
                    }else{
                        $.QuickAlert.alertFail({
                            content : "行政区划查询失败！"
                        });
                    }
                });

            };
            currentLocationHos();
//
//        $.JkcsUtils.nativePermission({
//            "type": "location",
//            "callBackMethod": "queryYyxx",
//            "params": params
//        });
//
//          setTimeout(function(){
//            }, 500);
        }
        function queryHosHandler(result,change) {
            /*    if(!requestYydm){
                    JSBridge.prototype.callHandler("setTitle",  {title: result.hosName});
                }*/
            if(change){
                page_treatment.queryScInfo(result);
                page_treatment.createYyxx(result);
                StoreCache.setCache("findHos",{isselecte:true,result});
            }else{
                page_treatment.queryScInfo(result.hospitals[0]);
                page_treatment.createYyxx(result.hospitals[0]);
                $("body").data("YYGH_HOSINFO",result.hospitals[0]);
                StoreCache.setCache("findHos",{isselecte:true,info:result.hospitals[0]});
            }
            var info = $("body").data("YYGH_HOSINFO");
            $.pageSwitch.clickToUrl("aside.hospital-list-box", "treatment", "hosCode="+info.hosCode);
            page_treatment.loadScImg();

        }

        function queryScInfo(sfsc2) {
            if (sfsc2 != undefined) sfsc = sfsc2;
        }

        /**创建top医院信息*/
        function createYyxx(yyxx) {
            if (!yyxx) yyxx = {};
            $("body").data("YYGH_HOSINFO", yyxx);
            $(".header-box").find("div.title").html(yyxx.hosName);
            var img='';
            if(yyxx["hosImgUrl"]){
                img =yyxx["hosImgUrl"];
            }else{
                img = "/static/images/teatment/jz-hospital-pic.png"
            }
            // yyxx["yyjbmc"] = tb_zy_yyjb[yyxx["hosGrade"]];
            // yyxx["yydjmc"] = tb_zy_yydj[yyxx["hosLevel"]];
            page_treatment.setSerachInfo("hosName",yyxx.hosName);
            page_treatment.setSerachInfo("hosCode",yyxx.hosCode);
            yyxx["yyjbmc"] = yyxx["hosGrade"];
            yyxx["isMedicareMc"] = yyxx["isMedicare"] == "0" ? "医保" : "非医保";
            $("aside.hospital-top-info").find("img").attr("src",img ).css({"height": "12rem"});
            $("aside.hospital-top-info, aside.hospital-top-text").find("span[name]").each(function () {
                var name = $(this).attr("name");
                var value = yyxx[name];
                $(this).text(value);
            });
        }

        /**收藏方法*/
        function scFunction() {
            // alert(1);
            var params = {};
            params["hosCode"] = $("body").data("YYGH_HOSINFO").hosCode;
            params["sfsc"] = sfsc;
            $.QuickRemote.AjaxJson("/api/jkcsHt/yygh/saveYyscInfo", function (result) {
                if (result["code"] == "0") {
                    sfsc = sfsc == 0 ? 1 : 0;
                    page_treatment.loadScImg();
                } else {
                    var content = sfsc == 0 ? "收藏医院失败！" : "取消收藏医院失败！";
                    $.QuickAlert.alertFail({content: content});
                }
            }, params);
        }

        /**加载收藏图片*/
        function loadScImg() {
            var title = $("title").html();
            var titleType = $("titleType").html();
            var params = {
                "title" : title
            };
            if(sfsc == "1"){
                params["scImg"] = "sc_red";
            }else{
                params["scImg"] = "sc_white";
            }
            if("change"== $.QuickUrlUtils.getRequest("type")){
                titleType = "jzPop";
            }
            var option = $.JkcsTile.getTitle(titleType,params);
            $.JkcsUtils.setHeader(option);
            $.JkcsUtils.loadScImg(sfsc);
        }
        function setSerachInfo(id,value){
            var info = StoreCache.getCache("searchInfo");
            if(!info){
                info={};
            }
            info[id]=value;
            StoreCache.setCache("searchInfo",info);
        }
        function toOrder(data){
            var info = $("body").data("YYGH_HOSINFO");
            if (data) {
                $.pageSwitch.goToUrl("myOrder","hosDetail","hosCode="+info.hosCode+"&"+data);
            } else {
                $.pageSwitch.goToUrl("myOrder","hosDetail","hosCode="+info.hosCode);
            }
        }
        var cfg_def = {
            onLocationComplete: onLocationComplete,
            initView: initView,
            initDataByYydm: initDataByYydm,
            initData: initData,
            queryHosHandler: queryHosHandler,
            queryScInfo: queryScInfo,
            createYyxx: createYyxx,
            scFunction: scFunction,
            loadScImg: loadScImg,
            setSerachInfo: setSerachInfo,
            toOrder: toOrder,
        }

        page_treatment.init = function(cfg){
            $.extend(page_treatment, cfg_def, cfg);
            page_treatment.initView();
            if (requestYydm){
                page_treatment.queryHosHandler(requestYydm,"change");
                StoreCache.setCache("reportYYDM",requestYydm);
            }
            else if(requestYydm2){
                page_treatment.initDataByYydm("451135959");
                StoreCache.setCache("reportYYDM","451135959");
            }

            else {
                page_treatment.initData();
            }
            $('#clickTo').click(function () {
                page_treatment.toOrder('HOSDETAIL_TAB=1')
            })


        }

        return page_treatment;
    })(jQuery, {});



</script>
</body>
</html>
